# geometry.two_d.quadrangle -- Module for Quadrangle geometry
#
# Copyright (c) 2000, V.Kelson and M.Bakker
# Copyright (c) 2001, W.J. Zaadnoordijk
#

import polygon

class Quadrangle(polygon.Polygon):
	'''Class for (horizontal) Quadrangle Geometry

	Python call: Quadrangle(vertices).'''

	# Class that holds a Quadrangle
	def __init__(self,vertices):
		'''Constructor

		Python call: Quadrangle(vertices). pt1 and pt2 are two opposing corners'''
		assert len(vertices)==4,"4 vertices required for Quadrangle"
		polygon.Polygon.__init__(self,vertices)

	def area(self):
		'''returns area'''
		CZ1=complex(self.vertices[0])
		CZ2=complex(self.vertices[1])
		CZ3=complex(self.vertices[2])
		CZ4=complex(self.vertices[3])
		CZT3=(CZ3-CZ1)/(CZ2-CZ1)
		CZT4=(CZ4-CZ1)/(CZ2-CZ1)
		l=abs(CZ2-CZ1)
		ksi3=CZT3.real
		ksi4=CZT4.real
		eta3=CZT3.imag
		eta4=CZT4.imag
		return 0.5*l*l*(((1-ksi3)*eta3)+((ksi3-ksi4)*(eta3+eta4)+ksi4*eta4))
